const Mock = require('mockjs')

const List = []

const data = Mock.mock({
  'items|6': [{
    'id|+1': 1,    //id
    userCode: 'U123',     //用户编号
    userName:'@cname',    //用户名称
    userGender:'@cword("男女")',  //性别
    'userRole|1':['管理员','普通用户'],    //用户角色
    userteleNumber:'17775337844',  //电话号码
    userEmail:'@email',     //邮箱
    'userState|1': ['启用','禁用'],      //用户状态
    userAccount:'account',
    userPassword:'password',
  }]
})

// List = items
for(let i=0;i < data.items.length;i++){
  List.push(data.items[i])
}

module.exports = [
  // 获取用户列表
  {
    url: '/vue-admin-template/userInfo/list',
    type: 'get',
    response: config => {
      const items = data.items
      return {
        code: 20000,
        data: {
          total: items.length,
          items: items
        }
      }
    }
  },

  //新增用户
  {
    url:'/vue-element-template/userInfo/add',
    type:'post',
    response: _ =>{
      return{
        code: 20000,
        data: 'success'
      }
    }
  },
  //修改用户
  {
    url:'/vue-element-template/userInfo/edit',
    type:'post',
    response: _ =>{
      return{
        code: 20000,
        data: 'success'
      }
    }
  },
  //查询用户
  {
    url: '/vue-element-template/userInfo/find',
    method: 'get',
    response:config =>{
      const {userCode,userName,userGender,userRole,userState} = config.query
      //list方法筛选
      // let mockList = List.filter(item =>{
      //   if(userCode&&item.userCode !== item.userCode) return false
      //   if(userGender&&item.userGender !==item.userGender) return false
      //   if(userName&&item.userName !== item.userName) return false
      //   if(userRole !== item.userRole) return false
      //   if(userState !== item.userState) return false
      //   return true 
      // })
      let mockList = List.filter(function(x){
        // return x.userCode === userCode
        return x.userGender === userGender||x.userCode == userCode||x.userName === userName||
               x.userRole === userRole|| x.userState === userState
      })

      // if(userCode === null&&userName===null&&userGender===null&&userRole==null&&userState==null){

      // }

      return{
        code: 20000,
        data:{
          total:mockList.length,
          items:mockList
          // items
        }
      }
    }
  },
]
